/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source 
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.  
 */

package jdbcmanager.tree;

import java.awt.*;

import jdbcmanager.app.*;
import jdbcmanager.dbtools.datatypes.*;
import jdbcmanager.swing.*;

/**
 * This is the root node.
 *
 * @author Francisco Morero Peyrona
 */
final class NodeDBMS extends JdbcTreeNode
{
   NodeDBMS( String sCaption )
   {
      super( icon_tree_server, new DbEntityDescriptor( null, null, sCaption ) );

      // Set Invalid Actions
      setOpenable(    false );
      setEditable(    false );
      setDeleteable(  false );
      setRefreshable( false );
      setInfoable(    false );
   }
   
   /**
    * Needed to be redefined because the status changes on the fly 
    */
   boolean isRefreshable()
   {
   	  return getChildCount() > 0;
   }
   
   boolean isInfoable()
   {
   	  return getChildCount() > 0;
   }

   // This node always has children
   boolean isInitialised()
   {
      return this.bWasInit;
   }

   boolean new_()
   {
      App.connect2DBMS( null );  // null -> open conneciton dialog
      return false;   // bacause connect2Server() already reloads the entire tree
   }

   void open()
   {
      // Redefined because was declared abstract in parent, but nothing to do
   }

   boolean edit()
   {
      // Redefined because was declared abstract in parent, but nothing to do
      return false;
   }

   boolean rename( String sNewName )
   {
      // Redefined because was declared abstract in parent, but nothing to do
      return false;
   }

   boolean delete()
   {
      // Redefined because was declared abstract in parent, but nothing to do
      return false;
   }

// This node only can contain children
   void info()
   {
      App.setCursor( Cursor.WAIT_CURSOR );
      String  sTitle = "Data Base Information";
       
      try
      {
         JxDialog dialog = new JxDialog( sTitle );
                  dialog.getContentPane().add( new Info4DBMS() );
                  dialog.pack();
                  dialog.center();
                  dialog.setVisibleButtonPanel( false );
                  dialog.setVisible( true );
      }
      catch( Throwable thr )
      {
         App.showException( thr, "Information not available: driver reported following error" );   
      }  
           
      App.restoreCursor();
   }
}